from flask import Flask,request
from flask import render_template
from reserch import reserch4letters


app = Flask(__name__)

#1.路由：相对路径，决定了 页面资源 的路径，如果没有登记，将返回404 not found
#1.1 url:相对于：http://127.0.0.1：5000的相对路径
#1.2 methods:[GET] [POST]
#2.视图函数:
#2.1 函数过程决定了你操作的方法（实现的功能），例如 if elief else for while...
#2.2 return:可以是txt文本，html文件(模板渲染)，可以是jsdn文件

#【GET】
@app.route('/',methods=['GET'])
def hello():  # put application's code here
    return render_template('hello.html')

@app.route('/index',methods=['GET'])
def index():  # put application's code here
    return render_template('index.html')

@app.route('/shopping_home',methods=['GET'])
def shopping_home():  # put application's code here
    return render_template('shopping_home.html')

@app.route('/drink',methods=['GET'])
def drink():  # put application's code here
    return render_template('drink.html')

@app.route('/index2',methods=['GET'])
def index2():  # put application's code here
    return render_template('index2.html')

#[POST]实现用户输入,点击提交，将数据提交到/result
@app.route('/result2',methods=['POST'])
def result2():

    py_firstname = request.form['firstname']
    py_lastname = request.form['lastname']
    py_fullname = py_firstname.title() + ' ' + py_lastname.title()

    return render_template('result2.html',
                           fullname=py_fullname)


@app.route('/result',methods=['POST'])
def result():

    py_word = request.form['word']
    py_vowels = request.form['vowels']
    py_found = reserch4letters(py_vowels,py_word)

    return render_template('result.html',
                           found = py_found)

@app.route('/shop_result',methods=['POST'])
def shop_result():

    py_iphone = request.form['iphone']
    py_denglu = py_iphone

    return render_template('shop_result.html',
                           dengji = py_denglu)

@app.route('/drink_result',methods=['POST'])
def drink_result():
    product_lists = [
        ("蓝莓饮料", "￥20"),
        ("橙汁", "￥15"),
        ("胡罗卜汁", "￥12"),
        ("蜜桃气泡水", "￥25"),
        ("特色苦瓜汁", "￥18"),
        ("抹茶星冰乐", "￥35"),
        ("鸡尾酒", "￥28"),
        ("柠檬茶", "￥15")
    ]

    return render_template('drink_result.html',product_lists=product_lists)

@app.route('/last', methods=['POST', 'GET'])
def last():

    name = request.form.get("name")
    tel = request.form.get('tel')
    add = request.form.get("add")
    lst = request.form.getlist('list')
    lst_str = "，".join(lst)
    return render_template('last.html',
                           name=name,
                           tel=tel,
                           add=add,
                           lst_name=lst_str)



if __name__ == '__main__':
    app.run()


